#ifndef _bll_h
#define _bll_h

//#include "../DAL/dal.h"
#include "wx/string.h"
/*#include "wx/treectrl.h"
#include "wx/imaglist.h"
#include "wx/statusbr.h"*/
/*#include "../Control/Control_Pref.h"
#include "../Control/ResultNotebook.h"
#include "../Control/EditNotebook.h"*/
//#include "../Editor/edit.h"
#include "../Control/MyUI.h"
#include "../Control/UIThread.h"

#include "pref.h"

class BLL {
public:
	BLL(){}
	static void AddDbListToTreeCtrl(MyUI* ui,bool initial,int pos);
	static void OnTreeCtrlActived(MyUI* ui,wxTreeItemId cur);
	static wxTreeItemId GetParentItemIdByLayer(wxTreeItemId cur,wxTreeCtrl* treeCtrl,int layer);
	static MYSQL* GetMySQLByTreeCtrlLayer(wxTreeItemId root,wxTreeCtrl* treeCtrl,EditNotebook* editNotebook);
	static void AddTableListToTreeCtrl(MYSQL*mysql,wxString db,wxTreeItemId cur,wxTreeCtrl* treeCtrl,wxStatusBar* s_bar,wxChoice* currentDbChoice);
	static bool CheckQueryResultList(QueryResultList* res);
	static float GetMySQLVersion(MYSQL* mysql);
	static void SetCurrentDb(MYSQL* mysql,wxStatusBar* s_bar,wxChoice* currentDbChoice);
	static int GetTreeCtrlLayer(wxTreeItemId root,wxTreeCtrl* treeCtrl);
	static void DoSQLQuery(MyUI* ui,const wxString& query,int type=0);
	static float FetchingData(ResultArray& array,MYSQL* mysql,wxString& query,wxStatusBar* s_bar,QueryResultList* resultList,QueryResult* cur,QueryResult* r);
	static void LoadingData(ResultArray& array,int sets_count,MYSQL* mysql,wxString& query,EditNotebook* editNotebook,ResultNotebook* result,wxStatusBar* s_bar,wxChoice* currentDbChoice,Edit* log,int type);
	//	extern	void _OnTreeCtrlActived(EditNotebook* editNotebook,wxTreeItemId cur,wxTreeCtrl* treeCtrl,wxStatusBar* s_bar,wxChoice* currentDbChoice,Edit* log,ResultNotebook* result);

	static void DoSQLQuery(MyUI* ui, int type);
};

//extern "C"{
extern	void _ReadConfList(wxChoice* lsSaved,ConfArray* array);
extern	wxString _GetMySQLError(MYSQL* mysql);
extern	MYSQL* _ConnectToMySQL(MYSQL* mysql,const wxString& host,wxString user,wxString passwd,wxString db,wxString port);
extern	void _SaveConf(wxString name,wxString ip,wxString user,wxString pwd,wxString port,wxString db);
extern	MYSQL* _InitMySQL(MYSQL* mysql);
/*


extern	void _AddDbListToTreeCtrl(MYSQL* mysql,wxTreeCtrl* treectrl,EditNotebook* editNotebook,wxString connInfo,wxChoice* currentDbChoice,bool initial=true,int pos=0);
extern	void _DoSQLQuery(MYSQL* mysql,wxString query,ResultNotebook* result,wxStatusBar* s_bar,wxChoice* currentDbChoice,Edit* log,int type=0,wxMutex* mutex=NULL);
extern	void _AddTableListToTreeCtrl(MYSQL*mysql,wxString db,wxTreeItemId cur,wxTreeCtrl* treeCtrl,wxStatusBar* s_bar,wxChoice* currentDbChoice);
extern	void _AttachListToTreeCtrl(MYSQL* mysql,wxString db,const char* query,wxTreeItemId cur,wxTreeCtrl* treeCtrl,TreeNodeType nodeType);
extern	void _ShowCreateRoutine(MYSQL* mysql,wxString db,wxString sp,ResultNotebook* result,RoutineType type);
extern	float _GetMySQLVersion(MYSQL* mysql);
extern	void _AddRoutineParmsToTreeCtrl(MYSQL* mysql,wxString db,wxString sp,wxTreeItemId cur,wxTreeCtrl* treeCtrl,ResultNotebook* result,TreeNodeType type,RoutineType rType);
extern	void _CloseMySQL(MYSQL* mysql);
extern	void _ShowCreateView(MYSQL* mysql,wxString db,wxString view,ResultNotebook* result);
extern	void _SetCurrentDb(MYSQL* mysql,wxStatusBar* s_bar,wxChoice* currentDbChoice);
extern	void _ExportResult(ResultNotebook* result,wxString filename);
extern	void _OnTreeCtrlActived(EditNotebook* editNotebook,wxTreeItemId cur,wxTreeCtrl* treeCtrl,wxStatusBar* s_bar,wxChoice* currentDbChoice,Edit* log,ResultNotebook* result);
extern	void _ChangeMySQLServer(MYSQL* mysql,wxTreeCtrl* treectrl,wxString connInfo,wxChoice* currentDbChoice,Edit* log);
extern	bool _CheckQueryResultList(QueryResultList* result);
extern	MYSQL* _GetMySQLByTreeCtrlLayer(wxTreeItemId cur,wxTreeCtrl* treeCtrl,EditNotebook* editNotebook);
extern	void _OnTreeCtrlReloadActived(int id,EditNotebook* editNotebook,wxTreeItemId cur,wxTreeCtrl* treeCtrl,wxStatusBar* s_bar,wxChoice* currentDbChoice,Edit* log,ResultNotebook* result);
extern	void _BindResultInText(ResultNotebook* result,ResultArray& array,int sets_count);
extern	int _GetTreeCtrlLayer(wxTreeItemId root,wxTreeCtrl* treeCtrl);
extern	void _OnPageChanged(int old_index,int new_index,EditNotebook* editNotebook,wxChoice* currentDbChoice,wxStatusBar* s_bar);
extern	void _AddNewConnection(wxTreeCtrl* treectrl,EditNotebook* editNotebook,wxChoice* currentDbChoice,wxStatusBar* s_bar);
extern	void _SetStatusBar(MYSQL* mysql,wxStatusBar* s_bar);
extern	void _FectingData(ResultArray& array,MYSQL* mysql,wxString& query,wxStatusBar* s_bar,QueryResultList* resultList,QueryResult* cur,QueryResult* r);
extern	void _LoadingData(ResultArray& array,int sets_count,MYSQL* mysql,wxString& query,ResultNotebook* result,wxStatusBar* s_bar,wxChoice* currentDbChoice,Edit* log,int type);
*/


#endif